﻿using Abp.AutoMapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AVIS.OutBound.Contents
{
    /// <summary>
    /// 特惠促销活动内容
    /// </summary>
    [AutoMapFrom(typeof(Content))]
    public class PromotionInfo : BaseCMS
    {
        /// <summary>
        /// 促销名称 （对应字段：Field1）
        /// </summary>
        public string Title { get; set; }

        /// <summary>
        /// 缩略图，首页图片 （对应字段：Field37）
        /// </summary>
        public string ThumbImageUrl
        {
            get
            {
                if (string.IsNullOrWhiteSpace(_ThumbImageUrl))
                {
                    return _ThumbImageUrl;
                }

                if (!_ThumbImageUrl.ToLower().StartsWith("http"))
                {
                    return SiteConfig.UploadImgUrl + _ThumbImageUrl;
                }

                return _ThumbImageUrl;
            }
            set
            {
                if (value != null)
                {
                    _ThumbImageUrl = value.ToLower();
                }
            }
        }
        private string _ThumbImageUrl = string.Empty;

        /// <summary>
        /// 摘要信息，首页概论 （对应字段：Field16）
        /// </summary>
        public string Summary { get; set; }

        /// <summary>
        /// 详细内容信息 （对应字段：Field46）
        /// </summary>
        public string Content
        {
            get
            {
                if (string.IsNullOrWhiteSpace(_Content))
                {
                    return _Content;
                }

                return _Content.Replace("/UpLoad/", SiteConfig.UploadUrl);
            }
            set
            {
                _Content = value;
            }
        }
        private string _Content = string.Empty;

        /// <summary>
        /// AWD等参数设置 （对应字段：Field2） 如：AWD=CNNAM90
        /// </summary>
        public string QueryString { get; set; }

        /// <summary>
        /// 友情链接图片（对应字段：Field36）
        /// </summary>
        public string LinkImage
        {
            get
            {
                if (string.IsNullOrWhiteSpace(_LinkImage))
                {
                    return _LinkImage;
                }

                if (!_LinkImage.ToLower().StartsWith("http"))
                {
                    return SiteConfig.UploadImgUrl + _LinkImage;
                }

                return _LinkImage;
            }
            set
            {
                if (value != null)
                {
                    _LinkImage = value.ToLower();
                }
            }
        }
        private string _LinkImage = string.Empty;

        /// <summary>
        /// 促销类型（对应字段：Field57）
        /// </summary>
        public string Type { get; set; }

        /// <summary>
        /// 从ContentCacheItem复制数据
        /// </summary>
        /// <param name="c"></param>
        /// <returns></returns>
        public PromotionInfo MapFrom(ContentCacheItem c)
        {
            base.MapFromContent(c);

            this.Title = c.Field1;
            this.QueryString = c.Field2;
            this.Summary = c.Field16;
            this.LinkImage = c.Field36;
            this.ThumbImageUrl = c.Field37;
            this.Content = c.Field46;
            this.Type = c.Field57;

            return this;
        }
    }
}
